package com.dk.service.impl;

import com.dk.dao.CarDaoJPA;
import com.dk.pojo.Car;
import com.dk.service.CarServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;


@Service
public class CarServiceImpl implements CarServiceI {

    @Autowired
    private CarDaoJPA carDao;

    //查询所有
    @Override
    public List<Car> findAll() {
        List<Car> carList = carDao.findAll();
        return carList;
    }

    @Override
    public Car findById(Integer carId) {
        Optional<Car> byId = carDao.findById(carId);
        Car car = byId.orElse(new Car());
        return car;
    }

    @Override
    public void deleteById(Integer carId) {
        carDao.deleteById(carId);
    }

    @Override
    public void updateCar(Car car) {
        carDao.save(car);
    }

    @Override
    public void saveCar(Car car) {

        carDao.save(car);
    }
}
